<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%@ page import="java.util.Calendar.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.sql.Date" %>
<%
//String requestTime =new SimpleDateFormat("hh:mm:ss a").format(new Date());
%>

<%//Grab the username and emp_id form the session
String uname=(String)session.getAttribute("userName");
String heading = request.getParameter("heading");
String description = request.getParameter("description");
//java.sql.Date d=java.sql.Date.valueOf(new Java.sql.Date());
//ddfa String emp_id=(String)session.getAttribute("emp_id");
out.println("the user here is "+uname);
%>
   <%
    Calendar calendar = Calendar.getInstance();
    %>
    

      
            
            <% //connect to database and set emp_id to the session
            int year=calendar.get(Calendar.YEAR);
            int month=calendar.get(Calendar.MONTH)+1;
            int day=calendar.get(Calendar.DAY_OF_MONTH);
            String query="insert into forumpost (heading,description,author,date,replies) values ('"+heading+"','"+description+"','"+uname+"','"+year+"-"+month+"-"+day+"','0')";
            Connection db_conn = null;
            Statement statement = null;
            PreparedStatement pstmt;
            ResultSet rs;
            try{
            Class.forName("com.mysql.jdbc.Driver");
            String url= "jdbc:mysql://localhost:3306/db";
            db_conn = DriverManager.getConnection( url,"root", "root" );
            statement = db_conn.createStatement();  
            statement.executeUpdate(query);
            db_conn.close();
            }
            catch(SQLException e){
            e.printStackTrace();
            out.println("sql not found");
            out.println(e);
            }
            catch(ClassNotFoundException e){
            e.printStackTrace();
            out.println(e);
            }
            %>






